<template>
<div>
<select-options  @search="search" :schoolyearOptions="schoolyearOptions" :semestersOptions="semestersOptions"
        :gradeOptions="gradeOptions" :subjectOptions="subjectOptions" :examinOptions="examinOptions" :t="t" ></select-options>
  <el-table :data="list" style="width: 100%;padding-top: 15px;">
    <el-table-column type="index" align="center" label="统计指标">
    </el-table-column>
    <el-table-column prop="schoolYear" align="center" label="语文"  >
    </el-table-column>
    <el-table-column prop="semester" align="center" label="数学"  >
    </el-table-column>
    <el-table-column prop="examname" align="center" label="外语"  >
    </el-table-column>
    <el-table-column prop="gradeenum" align="center" label="物理"  >
    </el-table-column>
    <el-table-column prop="graduationname" align="center" label="化学"  >
    </el-table-column>
  </el-table>
  </div>
</template>

<script>

import SelectOptions from '@/components/SelectOptions'
import axios from 'axios'
export default {
  components: {
    SelectOptions
  },
  data() {
    return {
      list: null,
      chartData: {},
      t: {
        schoolyear: '',
        semesters: '',
        grade: '',
        subject: '',
        examin: ''
      },
      schoolyearOptions: [],
      semestersOptions: [],
      gradeOptions: [],
      subjectOptions: [],
      examinOptions: []
    }
  },

  filters: {
    statusFilter(status) {
      const statusMap = {
        success: 'success',
        pending: 'danger'
      }
      return statusMap[status]
    }
  },

  created() {
    axios.post('/api/dashboard/selectOptions').then(response => {
      this.schoolyearOptions = response.data.schoolyear
      if (this.schoolyearOptions.length > 0) {
        this.t.schoolyear = this.schoolyearOptions[0].value
        this.schoolyear = this.schoolyearOptions[0].value
        this.$store.commit('SET_SCHOOLYEAR', this.schoolyearOptions[0].value)
      }
      this.semestersOptions = response.data.semester
      if (this.semestersOptions.length > 0) {
        this.t.semesters = this.semestersOptions[0].value;
        this.$store.commit('SET_SEMESTERS', this.semestersOptions[0].value)
      }
      this.gradeOptions = response.data.grade;
      if (this.gradeOptions.length > 0) {
        this.t.grade = this.gradeOptions[0].value
        this.$store.commit('SET_GRADE', this.gradeOptions[0].value)
      }
      this.subjectOptions = response.data.subject;
      if (this.subjectOptions.length > 0) {
        this.t.subject = this.subjectOptions[0].value
        this.$store.commit('SET_SUBJECT', this.subjectOptions[0].value)
      }
      this.examinOptions = response.data.examin;
      if (this.examinOptions.length > 0) {
        this.t.examin = this.examinOptions[0].value
      }
      this.init(this.t.schoolyear, this.t.semesters, this.t.grade, this.t.subject, this.t.examin)
    }).catch(error => {
      console.log(error)
    })
  },
  mounted() {


  },
  methods: {
    search: function(schoolyear, semesters, grade, subject, examin) {
      const formData = new FormData()
      formData.append('schoolyearenum_id', schoolyear)
      formData.append('semesterenum_id', semesters)
      formData.append('subject_id', subject)
      formData.append('gradeenum_id', grade)
      formData.append('examin', examin)
      // this.$store.dispatch('GetAllSignupDetail', signupInfo).
      axios.post('/api/dashboard/queryStuScore', formData).then(response => {
        // console.log(response)
        this.list = response.data.result
      }).catch(error => {
        console.log(error)
        this.$message.error('获取成绩统计失败，请稍后重试')
      })
    },
    init(schoolyear, semesters, grade, subject, examin) {
      const formData = new FormData()
      formData.append('schoolyearenum_id', schoolyear)
      formData.append('semesterenum_id', semesters)
      formData.append('subject_id', subject)
      formData.append('gradeenum_id', grade)
      formData.append('examin', examin)
      // this.$store.dispatch('GetAllSignupDetail', signupInfo).
      axios.post('/api/dashboard/queryStuScore', formData).then(response => {
        // console.log(response)
        this.list = response.data.result
      }).catch(error => {
        console.log(error)
        this.$message.error('获取成绩统计失败，请稍后重试')
      })
    }
  }

}
</script>
